<?php
include 'config.php';
ini_set('date.timezone','Asia/Shanghai');//调整时区
$hdid1=$config['hdid1'];//活动名称
$hdid2=$config['hdid2'];//活动名称
$time=$config['time'];//时间

$servername = "localhost";
$username = "root";
$password = "root";
$dbname = "data";

$conn = new mysqli($servername, $username, $password, $dbname);
// 检测连接
if ($conn->connect_error) {
    die("连接失败: " . $conn->connect_error);
}
//按群组分，入群人数和图片分享率
$sql="SELECT * , COUNT( * ) AS count, SUBSTRING(  `date` , 1, 15 ) AS dateindex FROM msg WHERE mtype =10000 and (hdid = '$hdid1'or hdid = '$hdid2') GROUP BY user_id HAVING  SUBSTRING(  `date` , 1, 10 )='$time' order by user_name asc";
$result = $conn->query($sql);//查询到的结果集
$total=array();//放置查询的数据
if ($result->num_rows > 0) {
    // 输出每行数据
    while($row = $result->fetch_assoc()) {
        if($row['count']>10){//群组超过10个人以上，才可以
            $name=$row['user_name'];//群组的名称
            //preg_match('/\d{1}\*\d+/',$name,$a);//只统计班级
            $data['user']=$name;
           // $data['user']=$name;
            $sql1="SELECT *  FROM msg WHERE mtype =3 and user_name='$name'";//在群里筛出图片分享数
            $res = $conn->query($sql1);
            $data['count']=$row['count'];
            $data['i_count']=$res->num_rows;
            $data['value']=round($data['i_count']/$data['count']*100,2);//计算出分享率
            $total[]=$data;
        }
    }
} else{
    echo "没有数据";
}
//$data1[]=$result->num_rows;
echo json_encode($total);
$conn->close();

?>